Skip to content

fix(windows): start Winsock at the first socket; 0.3.5 never did - #26

Merged
Sunrisepeak merged 1 commit into
masterfrom
fix/winsock-start
Nov 30, 2026
Merged

Sunrisepeak merged 1 commit into
masterfrom
fix/winsock-start

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

What

Socket::platform_init() (WSAStartup) existed and was never called anywhere in the library. On Windows the first connect therefore ran socket() / getaddrinfo() with Winsock unstarted: every request ended in statusCode = 0, statusText = "Connection failed", with nothing saying why. A program that uses the library as documented cannot make a single request on Windows.

Change

  • Socket::ensure_platform_started() — once per process, called at the top of Socket::connect, before the first socket() or getaddrinfo().
  • Socket::platform_started() — says whether it ran.
  • tests/test_winsock_start.cpp — a program whose first socket is the test's own: platform_started() is false, then a connect to the loopback's port 1 (refused at once by a started Winsock) makes it true. Runs on every platform; the flag semantics are the same, the WSAStartup is Windows-only.

platform_init() stays as it was (public API).

Verification

  • mcpp test winsock_start on Windows (clang 23.1.3, MSVC STL): test_winsock_start ... ok.
  • The same fix, applied from the outside by a program that called Socket::platform_init() itself, turned "Connection failed" on every request into real answers (401/403 from api.github.com) in gitxxx before this PR; this PR moves it where it belongs.

Authorship: ai-and-human

…ry request failed

Socket::platform_init() existed and was never called. On Windows the first connect then failed with WSANOTINITIALISED, reported as status 0 'Connection failed'. Socket::ensure_platform_started() runs once per process at the top of connect (before socket() and getaddrinfo); Socket::platform_started() reports it; tests/test_winsock_start.cpp is the first socket of its process and checks both.
@Sunrisepeak
Sunrisepeak merged commit 7d463ae into master Nov 30, 2026
10 checks passed
@Sunrisepeak
Sunrisepeak deleted the fix/winsock-start branch November 30, 2026 21:32
Sunrisepeak added a commit that referenced this pull request Nov 30, 2026
Co-authored-by: Sunrisepeak <Sunrisepeak@users.noreply.github.com>
Sunrisepeak added a commit to Sunrisepeak/xgit that referenced this pull request Nov 30, 2026
…s now

- tinyhttps 0.3.6 starts Winsock at the first socket itself (mcpplibs/tinyhttps#26),
  so the transport no longer does it on the library's behalf.
- src/sha256.cppm wraps mcpplibs.mwrap.mbedtls (the wrap opened from this work,
  now in the index as mcpplibs/mcpp-index#935) instead of its own FIPS 180-4
  arithmetic; the known-answer tests stay as they were.
- compat.mbedtls is one version for the graph, 3.6.8 (the wrap's; tinyhttps asks
  for 3.6.1, and two versions of a C source package cannot share one build).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant